from rest_framework import serializers
from api.models import Article,Tag

class ArticleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = '__all__'

class NewArticleSerializer(serializers.ModelSerializer):
    tag_info = serializers.SerializerMethodField()
    class Meta:
        model = Article
        fields = '__all__'

    def get_tag_info(self, obj):
        # return [row.title for row in obj.tag.all()]
        return [row for row in obj.tag.all().values('id', 'name')]

class FormNewArticleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = '__all__'

class TagSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tag
        fields = ['id', 'name']